<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>
        blogs
    </title>
    
<link rel="stylesheet" href="/libs/highlight/styles/monokai-sublime.css">

    
<link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">

    
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body id="bodyx">
    <div class="hd posts">
    <a href="/index.html"><i class="fa fa-reply replay-btn" aria-hidden="true"></i></a>
    <div class="post-title">
        <p>
            python环境搭建
        </p>
        <hr>
    </div>
    <div class="post-content">
        <h1 id="一、python的安装"><a href="#一、python的安装" class="headerlink" title="一、python的安装"></a>一、python的安装</h1><ul>
<li>下载官网地址 <a href="http://www.python.org" target="_blank" rel="noopener">www.python.org</a><br><img src="https://img-blog.csdnimg.cn/20200302112705919.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></li>
<li>选择安装版本 （3.7.6）<br><img src="https://img-blog.csdnimg.cn/20200302112802288.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></li>
<li>解压到我们电脑的具体盘符下的一个文件夹下<br><img src="https://img-blog.csdnimg.cn/20200302113603934.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></li>
<li>cmd测试安装配置是否完成（交互模式）<br><img src="https://img-blog.csdnimg.cn/20200302113630608.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><h1 id="二、python库的安装"><a href="#二、python库的安装" class="headerlink" title="二、python库的安装"></a>二、python库的安装</h1></li>
<li>安装pip</li>
<li>我们先要安装pip。<ul>
<li>安装pip先要下载get-pip.py，文件地址如下：<a href="https://bootstrap.pypa.io/get-pip.py，复制文件地址到浏览器（我用的是Google" target="_blank" rel="noopener">https://bootstrap.pypa.io/get-pip.py，复制文件地址到浏览器（我用的是Google</a> Chrome）地址栏<br><img src="https://img-blog.csdnimg.cn/20200302114045755.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></li>
</ul>
</li>
<li>另存为<br><img src="https://img-blog.csdnimg.cn/20200302114452723.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></li>
<li>安装pip步骤</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1、 进入pythonCoding&#x2F;python3.7.6目录</span><br><span class="line">2、输入命令安装 python get-pip.py</span><br><span class="line">3、找到E:\PythonCoding\Python64.3.7.5目录下python37._pth文件用记事本打开，将# import site前的#号删除，保存退出。</span><br></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/2020030211465012.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTk2MzIyMA==,size_16,color_FFFFFF,t_70" alt="安装pip开始"></p>
<ul>
<li>将E:\PythonCoding\Python64.3.7.6\Scripts添加到环境变量Path中。运行pip，如下图。</li>
<li>通过pip安装库</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">1、pip install numpy</span><br><span class="line">2、pip安装软件包需要pip安装源。国外的源下载速度太慢，经常出现下载安装出错。所以把pip安装源替换成国内镜像，可以大幅提升下载速度和安装成功率</span><br><span class="line">清华：https:&#x2F;&#x2F;pypi.tuna.tsinghua.edu.cn&#x2F;simple</span><br><span class="line">阿里云：https:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;pypi&#x2F;simple&#x2F;</span><br><span class="line">豆瓣：https:&#x2F;&#x2F;pypi.douban.com&#x2F;simple</span><br><span class="line">E:\Program Files\PythonCoding\python3.7.6\</span><br><span class="line"></span><br><span class="line">%USERPROFILE%\AppData\Local\Microsoft\WindowsApps  &#x2F;&#x2F;跳转商店</span><br></pre></td></tr></table></figure>
<ul>
<li>配置镜像源<br>pip config set global.index-url <a href="https://pypi.douban.com/simple" target="_blank" rel="noopener">https://pypi.douban.com/simple</a></li>
<li>库的使用<ul>
<li>库有标准库、扩展库、自定义库。标准库是内置库，无须安装，如Tkinter、math等，扩展库没有内置，需要安装，如numpy，安装命令如pip install numpy。</li>
<li>在库的使用方面，Python也与其他编程语言一样，需要先导入再使用，语法是：</li>
</ul>
</li>
<li>import 库名</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">from math import sin   # import之后就能正常使用库的资源了。</span><br><span class="line"></span><br><span class="line">sin(3.1415926)</span><br></pre></td></tr></table></figure>

<h1 id="三、vscode配置环境"><a href="#三、vscode配置环境" class="headerlink" title="三、vscode配置环境"></a>三、vscode配置环境</h1><p>lauch.json</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">            <span class="attr">"name"</span>:<span class="string">"Python : Current File"</span>,</span><br><span class="line">            <span class="attr">"pythonPath"</span>: <span class="string">"E:\\Program Files\\PythonCoding\\python3.7.6"</span>,</span><br><span class="line">            <span class="attr">"program"</span>: <span class="string">"$&#123;file&#125;"</span></span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>



<p>settings.json</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;window.zoomLevel&quot;: 1,</span><br><span class="line">    &quot;git.autofetch&quot;: true,</span><br><span class="line">    &quot;editor.suggestSelection&quot;: &quot;first&quot;,</span><br><span class="line">    &quot;vsintellicode.modify.editor.suggestSelection&quot;: &quot;automaticallyOverrodeDefaultValue&quot;,</span><br><span class="line">    &quot;breadcrumbs.enabled&quot;: true,</span><br><span class="line">    &quot;workbench.activityBar.visible&quot;: true,</span><br><span class="line">    &quot;editor.minimap.enabled&quot;: true,</span><br><span class="line">    &quot;workbench.sideBar.location&quot;: &quot;left&quot;,</span><br><span class="line">    &quot;files.autoSave&quot;: &quot;afterDelay&quot;,</span><br><span class="line">    &quot;javascript.updateImportsOnFileMove.enabled&quot;: &quot;always&quot;,</span><br><span class="line">    &quot;terminal.integrated.shell.windows&quot;: &quot;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe&quot;,</span><br><span class="line">    &quot;liveServer.settings.donotShowInfoMsg&quot;: true,</span><br><span class="line">    &quot;workbench.iconTheme&quot;: &quot;vscode-icons&quot;,</span><br><span class="line">    &quot;workbench.colorTheme&quot;: &quot;Material Theme&quot;,</span><br><span class="line">    &quot;vsicons.dontShowNewVersionMessage&quot;: true,</span><br><span class="line">    &quot;python.pythonPath&quot;: &quot;E:\\Program Files\\PythonCoding\\python3.7.6\\python.exe&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>
    
        <hr class="fhr">
        <div id="vcomments"></div>
    
</div>
    <div class="footer" id="footer">
    <p>Copyright © 2020 <a class="flink" href="https://hexo.io" target="_blank" rel="noopener">Hexo</a>-<a class="flink" href="https://github.com/sanjinhub/hexo-theme-geek" target="_blank" rel="noopener">Geek</a>.
        <label class="el-switch el-switch-green el-switch-sm" style="vertical-align: sub;">
            <input type="checkbox" name="switch" id="update_style">
            <span class="el-switch-style"></span>
        </label>
<!--         <script type="text/javascript">
        var cnzz_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");
        document.write(unescape("%3Cspan id='cnzz_stat_icon_1278548644'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "v1.cnzz.com/stat.php%3Fid%3D1278548644%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
        </script> -->
    </p>
</div>
<input type="hidden" id="web_style" value="black">
<input type="hidden" id="valine_appid" value="oU6aM6U9xOv4LHEQLo3LLROT-gzGzoHsz">
<input type="hidden" id="valine_appKey" value="TbfimrkuMCSYC9BPMRdOqKga">

<script src="/libs/jquery.min.js"></script>


<script src="/libs/highlight/highlight.pack.js"></script>

<script src='//cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>

<script src="/js/js.js"></script>

<style type="text/css">
.v * {
    color: #698fca;
}

.v .vlist .vcard .vhead .vsys {
    color: #3a3e4a;
}

.v .vlist .vcard .vh .vmeta .vat {
    color: #638fd5;
}

.v .vlist .vcard .vhead .vnick {
    color: #6ba1ff;
}

.v a {
    color: #8696b1;
}

.v .vlist .vcard .vhead .vnick:hover {
    color: #669bfc;
}
</style>
</body>

</html>